<template>
  <div class="main">
    <mine-title>项目详情</mine-title>
    <div class="content" v-loading="loading">
      <el-row :gutter="20">
        <el-col :span="12">
          <div>
            <el-form ref="form" :model="form" label-width="110px" :rules="rules">
              <el-form-item label="项目名称：" prop="itemName">
                <el-input v-model="form.itemName" size="small" clearable></el-input>
              </el-form-item>
              <el-form-item label="项目详情：" prop="detailed">
                <el-input  type="textarea" v-model="form.detailed" size="small" clearable></el-input>
              </el-form-item>
              <el-form-item label="所属单位：" prop="unit">
                <el-input  v-model="form.unit" size="small" clearable></el-input>
              </el-form-item>
              <el-form-item label="模型数量：" prop="modelCount">
                <el-input-number v-model="form.modelCount" size="small" clearable></el-input-number>
              </el-form-item>
              <el-form-item label="画布数量：" prop="canvasCount">
                <el-input-number v-model="form.canvasCount" size="small" clearable></el-input-number>
              </el-form-item>
              <el-form-item label="创建人：" prop="creator">
                <el-input  v-model="form.creator" size="small" clearable></el-input>
              </el-form-item>
              <el-form-item label="备注：" prop="remarks">
                <el-input type="textarea" v-model="form.remarks"></el-input>
              </el-form-item>
              <el-form-item class="form-btn-row">
                <mine-button type="primary" @click="onCancel" secondary>取 消</mine-button>
                <mine-button type="primary" @click="onSubmit">保 存</mine-button>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <el-col :span="12">
        </el-col>
      </el-row>

    </div>
  </div>
</template>

<script>
import request from '@/modules/index/utils/request';
import _ from 'lodash';
export default {
  name: "itemDetail",
  data() {
    return {
      form: {
        itemName: '',
        detailed: '',
        unit: '',
        modelCount: '',
        canvasCount: '',
        creator: '',
        createTime: new Date(),
        remarks: '',
        id:''
      },
      rules: {
        itemName: [
          { required: true, message: '请填写项目名称', trigger: 'blur' },
        ]
      },
      loading: false,
    }
  },
  computed: {
  },
  methods: {
    async init () {
      await this.getInstance();
    },
    getInstance: async function () {
      let id = this.$route.query.id;
      let params = id;
      try {
        this.loading = true;
        const res = await this.$store.dispatch('itemListById', params);
        const result = res.data || {};
        if (result.success) {
          const data = result.data || {};
          this.form = data;
          this.loading = false;
        }
      } catch (e) {
        console.error(e);
        this.loading = false;
      }
    },
    onSubmit() {
      let _this = this;
      this.$refs.form.validate(async (valid, object) => {
        let { form, equipCode, equipName, equipUse } = _this;
        if (valid) {
          this.loading = true;
          request({
            url: 'itemInfo/saveOrUpdate', //接口
            method: 'post',
            data: form,
          }).then((response) => {
            let result = response.data;
            if (!result.success) {
              this.loading = false;
              return;
            }
            this.$confirm('保存成功，是否需要返回列表？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            })
              .then(() => {
                this.$router.push('/itemAdmin');
              })
              .catch(() => {
                  this.loading = false;
              });
            // _this.onSubmitFile(result.data.id);
          });
        } else {
          return false;
        }
      });
    },
    onCancel() {
      this.$router.push('/itemAdmin');
      this.form = {
        itemName: '',
        detailed: '',
        unit: '',
        modelCount: '',
        remark: '',
        id:''
      };
    },
  },
  created() {
    this.init();
    this.$store.commit('SET_BREADCRUMB', [
      { title: '项目管理', path: '/itemAdmin' },
      { title: '项目详情', path: '' }
    ]);
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>
